package com.wanmait.wisdom.web.controller;

import com.github.pagehelper.PageInfo;
import com.wanmait.wisdom.entity.Car;
import com.wanmait.wisdom.util.AjaxResult;
import com.wanmait.wisdom.web.service.WebCarService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("web")
public class WebCarController {
    @Resource
    private WebCarService webCarService;

    @PostMapping("addinsert")
    public AjaxResult addinsert(@RequestBody Car car) {
        webCarService.insertCar(car);
        return AjaxResult.success();
    }

    @PostMapping("selectAllcar")
    public AjaxResult selectAllcar(@RequestBody Car car, Date startTime, Date endTime, Integer pageNum) {
        if (pageNum == null) {
            pageNum = 1;
        }
        int pageSize = 10;
        PageInfo<Car> pageInfo = webCarService.selectAllCar(car, startTime, endTime, pageNum, pageSize);
        return AjaxResult.success().put("pageInfo", pageInfo);
    }
    @PostMapping("addcar")
    public  AjaxResult addcar(@RequestBody Car car){
        webCarService.insertCar(car);
        return AjaxResult.success().put("car",car);
    }
}

